//
//  KWTMGRNSettingChgTimeCell.m
//  RuiHeApp
//
//  Created by Yan Chen on 2024/8/2.
//

#import "KWTMGRNSettingChgTimeCell.h"

@interface KWTMGRNSettingChgTimeCell()

@property (nonatomic, strong) QMUILabel *titleLab;

@property (nonatomic, strong) QMUITextField *leftTextField;

@property (nonatomic, strong) QMUILabel *timeLab;

@property (nonatomic ,strong) UIImageView *icon;

@property (nonatomic, strong) QMUILabel *stateLab;

@property (nonatomic, strong) QMUILabel *socLab;

@property (nonatomic, strong) QMUILabel *powerTitleLab;

@property (nonatomic, strong) QMUILabel *powerLab;

@end
@implementation KWTMGRNSettingChgTimeCell


-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}


-(void)setModel:(KWTMGRNSettingModel *)model
{
    _model = model;
    self.titleLab.text = model.rowTitle.rh_localized;
    
    KWTMGRNSettingModel *beginModel = [model.items safeObjectAtIndex:0];
    KWTMGRNSettingModel *endModel = [model.items safeObjectAtIndex:1];
    self.timeLab.text = [NSString stringWithFormat:@"%@-%@",ValidNullData(beginModel.content),ValidNullDataToString(endModel.content, @"-")];
    //充电,放电,靜置
    KWTMGRNSettingModel *modeModel = [model.items safeObjectAtIndex:2];
    self.stateLab.text = modeModel.enumText.rh_localized;
    self.stateLab.textColor = [modeModel.content integerValue]?kCOLOR_HEX(@"#31D3AE"):kCOLOR_HEX(@"#678EF2");
    
    //截止soc
    KWTMGRNSettingModel *socModel =  [model.items safeObjectAtIndex:3];
    self.socLab.text = [NSString stringWithFormat:@" %@%%",ValidNullDataToString(socModel.content, @"--")];
    //充放电功率
    KWTMGRNSettingModel *powerModel =  [model.items safeObjectAtIndex:4];
    self.powerLab.text = [NSString stringWithFormat:@" %@W",ValidNullDataToString(powerModel.content, @"--")];
    
    BOOL isChg = [modeModel.content integerValue]>0;
    self.icon.image = [UIImage imageNamed:isChg?@"setting_chg":@"setting_dchg"];
    
    //静置
    if (modeModel.content.length == 0 || modeModel.content.integerValue == 2) {
//        self.stateLab.text = @"静置".rh_localized;
        self.stateLab.textColor = kCOLOR_HEX_A(@"#171A1D",0.6);
        self.icon.image = [UIImage imageNamed:@"setting_chg_none"];
    }
}

-(void)setupUI
{
    kWeakSelf;
    self.contentView.backgroundColor = kCOLOR_HEX(@"#F0F5FF");
    UIView *bgView = [[UIView alloc]init];
    bgView.backgroundColor = UIColor.whiteColor;
    [self.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 15, 0, 15));
    }];
    
    QMUILabel *titleLab = [QMUILabel labelWithText:@"" font:kSYSTEMFONT(16) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    [bgView addSubview:titleLab];
    self.titleLab = titleLab;
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(10);
        make.left.mas_offset(15);
    }];
    
    
    UIImageView *arrow1 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow_2"]];
    [bgView addSubview:arrow1];
    [arrow1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(18);
        make.centerY.equalTo(weakSelf.titleLab);
        make.right.mas_offset(-15);
    }];
    
    UIView *bottom_bgView = kView;
    bottom_bgView.backgroundColor = kCOLOR_HEX(@"#F3F7FF");
    bottom_bgView.layer.cornerRadius = 8;
    bottom_bgView.layer.masksToBounds = YES;
    [bgView addSubview:bottom_bgView];
    [bottom_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.top.equalTo(weakSelf.titleLab.mas_bottom).offset(10);
        make.bottom.mas_offset(-15);
    }];
    
    
    
    _icon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"setting_chg"]];
    [bottom_bgView addSubview:_icon];
    [_icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(24);
        make.top.mas_offset(15);
        make.left.mas_offset(15);
    }];
    
    _timeLab = [QMUILabel labelWithFont:kSYSTEMFONT(16) textColor:kCOLOR_HEX(@"#171A1D") textAligment:NSTextAlignmentLeft];
    [bottom_bgView addSubview:_timeLab];
    [_timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.icon.mas_right).offset(5);
        make.centerY.equalTo(weakSelf.icon);
    }];
    
    _stateLab = [QMUILabel labelWithFont:kSYSTEMFONT(14) textColor:kCOLOR_HEX(@"#31D3AE") textAligment:NSTextAlignmentRight];
    _stateLab.text = @"--";
    [bottom_bgView addSubview:_stateLab];
    [_stateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-15);
        make.centerY.equalTo(weakSelf.icon);
    }];
    
    QMUILabel *socTitleLab = [QMUILabel labelWithText:@"SOC:" font:kSYSTEMFONT(14) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    [bottom_bgView addSubview:socTitleLab];
    [socTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.timeLab);
        make.top.equalTo(weakSelf.icon.mas_bottom).offset(15);
        make.bottom.mas_offset(-15);
    }];
    
    _socLab = [QMUILabel labelWithText:@"--" font:kSYSTEMFONT(14) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    [bottom_bgView addSubview:_socLab];
    [_socLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(socTitleLab.mas_right);
        make.centerY.equalTo(socTitleLab);
    }];
    
    _powerTitleLab = [QMUILabel labelWithText:[NSString stringWithFormat:@"%@:",@"功率".rh_localized] font:kSYSTEMFONT(14) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    [bottom_bgView addSubview:_powerTitleLab];
 
    [_powerTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bottom_bgView.mas_centerX).offset(5);
        make.centerY.equalTo(socTitleLab);
       
    }];
    
    _powerLab = [QMUILabel labelWithText:@"--" font:kSYSTEMFONT(14) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
    [bottom_bgView addSubview:_powerLab];
    [_powerLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.powerTitleLab.mas_right);
        make.centerY.equalTo(weakSelf.powerTitleLab);
    }];
    
    
    QMUIButton *leftBtn = [[QMUIButton alloc]init];
    [bgView addSubview:leftBtn];
    [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
    }];
    

    [[leftBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        if (weakSelf.selectAction) {
            weakSelf.selectAction(weakSelf.model);
        }
    }];
    
}
@end
